<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>{$info['title']}预订-{$webname}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    {Common::css('swiper.min.css,mobilebone.css,base.css,header.css,footer.css')}
    {Common::css_plugin('spot.css','spot')}
    {Common::js('jquery.min.js,lib-flexible.js,swiper.min.js,mobilebone.js,delayLoading.min.js,jquery.layer.js,validate.js,layer2.0/layer.js,stmath.js')}
</head>

<body>
<div class="page" id="pageHome" data-title="预订产品">
    {request "pub/header_new/typeid/$typeid/isbookpage/1"}
    <!-- 公用顶部 -->
    <div class="page-content">
            <div class="wrap-content">
                <form action="{$cmsurl}spot/create" id="orderfrm" method="post">
                    {if empty($userinfo['mid'])}
                    <div class="login-hint-txt">
                        温馨提示：<a class="login-link" href="{$cmsurl}member/login" data-ajax="false">登录</a>可享受预订送积分、积分抵现！
                    </div>
                    {/if}
                    <!-- 温馨提示 -->

                    <div class="booking-info-block clearfix">
                        <h3 class="block-tit-bar"><strong>预订信息</strong></h3>
                        <div class="spot-name-block">
                            <div class="tit">{$suit_info['title']}</div>
                            <div class="info">产品编号：{$suit_info['series']}</div>
                            <div class="info">景点名称：{$info['title']}</div>
                            <div class="info" id="ticketInfoentry">门票说明<i class="more-icon"></i></div>
                        </div>
                        <div class="block-item">
                            <ul>
                                <li class="choose-date-bar">
                                    <strong class="item-hd">使用日期</strong>
                                    <span class="more-type" id="chooseBookingDate">
                                        {loop $next_price $cur_suit}
                                        <span class="item-date" data-date="{$cur_suit['date']}" data-total="{$cur_suit['number']}" data-price="{$cur_suit['price']}">
                                            <span class="date">{if $cur_suit['date']==date('Y-m-d',time())}今天{elseif $cur_suit['date']==date('Y-m-d',strtotime('+1 day'))}明天{/if}{date('m-d',$cur_suit['day'])}</span>
                                            <span class="pri">{Currency_Tool::symbol()}{$cur_suit['price']}</span>
                                        </span>
                                        {/loop}
                                        <a href="#choose_date" class="item-date">
                                            <span class="date">更多日期<i class="more-icon"></i></span>
                                            {php}$min_price=Model_Spot::get_minprice($suit_info['spotid'], $suit_info['id']);{/php}
                                            <span class="pri">{Currency_Tool::symbol()}{$min_price['price']}起</span>
                                        </a>
                                    </span>
                                </li>
                                <li>
                                    <strong class="item-hd">门票数量</strong>
                                    <span class="amount-opt-wrap">
                                        <a href="javascript:;" class="sub-btn">–</a>
                                        <input type="text" name="dingnum" id="field_dingnum" readonly class="num-text" maxlength="4" value="1">
                                        <a href="javascript:;" class="add-btn">+</a>
                                    </span>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <!-- 预订信息 -->

                    <div class="booking-info-block clearfix">
                        <h3 class="block-tit-bar"><strong>订单联系人</strong></h3>
                        <div class="block-item">
                            <ul>
                                <li>
                                    <strong class="item-hd">联系人：</strong>
                                    <input type="text" name="linkman" id="field_linkman" class="write-info" placeholder="请填写真实姓名" value="{$userinfo['truename']}" />
                                    <span class="nd">(必填)</span>
                                </li>
                                <li>
                                    <strong class="item-hd">手机号码：</strong>
                                    <input type="text" name="linktel" id="field_linktel" class="write-info" placeholder="请输入常用手机号码"  value="{$userinfo['mobile']}" />
                                    <span class="nd">(必填)</span>
                                </li>
                            </ul>
                        </div>
                        <div class="block-remarks">
                            <strong class="item-hd">订单备注：</strong>
                            <textarea class="item-txt" name="remark"></textarea>
                        </div>
                    </div>
                    <!-- 订单联系人 -->
                    {if $suit_info['fill_tourer_type']!=='0'}
                    <div class="booking-info-block clearfix" id="tourer_con"{if $suit_info['fill_tourer_type']==1} data-max="1"{/if}{if $suit_info['fill_tourer_items']} data-field="{$suit_info['fill_tourer_items']}"{/if}>
                        <h3 class="block-tit-bar">
                            <strong>游客信息</strong>
                            {if !empty($userinfo['mid'])}<a class="yk-check-link fr" href="#commonUse">选择常用游客<i class="more-ico"></i></a>{/if}
                        </h3>
                        <div class="block-item">

                        </div>
                    </div>
                    {/if}
                    <!-- 游客信息 -->


                    <!-- 优惠政策 -->
                    {if !empty($userinfo)}
                    {request "spot/discount/productid/".$info['id']}
                    {/if}
                    <!-- 优惠信息 -->

                    <input type="hidden" name="suitid" id="field_suitid"/>
                    <input type="hidden" name="productid" id="field_productid" value="{$info['id']}"/>
                    <input type="hidden" id="field_price" value="0"/>

                    <input type="hidden" id="field_dingjin" value="0"/>
                    <input type="hidden" id="field_paytype" value="1"/>
                    <input type="hidden" name="startdate" id="field_startdate" value=""/>
                    <input type="hidden" id="org_total_price" value="0"/>
                    <input type="hidden" id="couponid" name="couponid" value=""/>
                    <input type="hidden" id="coupon_price" value="0"/>
                    <input type="hidden" id="max_useful_jifen" value="{if $jifentprice_info['toplimit']>$userinfo['jifen']}{$userinfo['jifen']}{else}{$jifentprice_info['toplimit']}{/if}"/>
                    <input type="hidden" id="jifentprice_limit" value="{$jifentprice_info['toplimit']}"/>
                    <input type="hidden" id="jifentprice_price" value="{$jifentprice_info['jifentprice']}"/>
                    <input type="hidden" id="jifentprice_exchange" value="{$jifentprice_info['cfg_exchange_jifen']}"/>
                    <input type="hidden" id="needjifen" name="needjifen"  value="0"/>

            <input type="hidden" id="envelope_price" value=""/>
            <input type="hidden" name="envelope_member_id"  id="envelope_member_id"  value="0"/>

            {St_Product::form_token()}

                    <div class="booking-info-block clearfix">
                        <div class="block-item">
                            <ul>
                                <li>
                                    <strong class="item-hd">支付方式</strong>
                                    <span class="more-type" id="txt_paytype"></span>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <!-- 支付方式 -->
                    {if $GLOBALS['cfg_spot_order_agreement_open']==1}
                    <div class="agreement-block">
                        <i class="check-box{if $GLOBALS['cfg_spot_order_agreement_selected']!=='0'} on{/if}"></i>我已阅读并同意<a href="#bkDocumentContent">《预订须知》</a>
                    </div>
                    {/if}
                </form>
                <!-- 预订协议 -->
                {if $GLOBALS['cfg_spot_order_agreement_open']==1}
                <input type="hidden" id="agreement_order" name="agreement_order"  value="{$GLOBALS['cfg_spot_order_agreement_selected']}"/>
                {/if}
            </div>

        <div class="bom-fixed-content">
            <div class="bom-fixed-block">
                    <span class="total">
                        <em class="jg no-style" id="bbar_paytotal"></em>
                    </span>
                <span class="order-show-list" id="order-show-list">明细<i class="arrow-up-ico"></i></span>
                <a class="now-booking-btn" href="javascript:;">立即预订</a>
            </div>
        </div>
        <!-- 立即预订 -->

        <div class="fee-box" id="fee-box" style="display: none;">
            <div class="fee-container">
                <div class="fee-row">
                    <p class="ze">
                        <strong class="no-style">应付总额</strong>
                        <em class="fr no-style" id="board_total"></em>
                    </p>
                    <p class="sm hide" id="board_dingjin"></p>
                </div>
                <ul class="mx-list">
                    <li>
                        <strong id="board_suitname" class="no-style"></strong>
                        <em id="board_org_total" class="no-style"></em>
                    </li>
                    <li>
                        <span class="zk">-(扣减)</span>
                    </li>
                    <li class="board_discount">
                        <strong class="no-style">积分抵现</strong>
                        <em id="board_jifentprice" class="no-style">0</em>
                    </li>
                    <li class="board_discount">
                        <strong class="no-style">优惠券</strong>
                        <em id="board_coupon" class="no-style">{Currency_Tool::symbol()}0</em>
                    </li>
                    {if St_Functions::is_normal_app_install('red_envelope')}
                    <li class="board_discount">
                        <strong class="no-style">红包抵扣</strong>
                        <em class="no-style" id="board_envelope">{Currency_Tool::symbol()}0</em>
                    </li>
                    {/if}
                </ul>
            </div>
        </div>
        <!-- 费用明细 -->

        <div class="foo-box hide" id="cardtype_con">
            <div class="foo-container">
                <ul class="list">
                    <li>护照</li>
                    <li>身份证</li>
                    <li>台胞证</li>
                    <li>港澳通行证</li>
                    <li>军官证</li>
                    <li>出生日期</li>
                </ul>
            </div>
        </div>
        <!-- 证件选择 -->
        <div class="foo-box hide" id="suit_list">
            <div class="tc-container">
                <div class="tc-tit-bar"><strong class="bt no-style">选择套餐</strong><i class="close-icon"
                                                                                    onclick="$('#suit_list').hide()"></i>
                </div>
                <div class="tc-wrapper">
                    <ul>
                        {st:spot action="suit" productid="$info['id']"}
                        {loop $data $suit}
                        <li class="suit_item_{$suit['id']}" data-id="{$suit['id']}"
                            date-start="{date('Y-m-d',$suit['startTime'])}" data-suitname="{$suit['title']}"
                            data-paytype="{$suit['paytype']}" data-paytype_name="{$suit['paytype_name']}"
                            data-price="{$suit['ourprice']}" data-dingjin="{$suit['dingjin']}"><em
                                    class="item no-style">{$suit['title']}</em><i class="radio-btn"></i></li>
                        {/loop}
                    </ul>
                </div>
            </div>
        </div>
        <!--套餐选择 -->
    </div>
</div>
<!--预订-->
{if $GLOBALS['cfg_spot_order_agreement_open']==1}
<div class="page out" id="bkDocumentContent">
    <header>
        <div class="header_top">
            <a class="back-link-icon" href="#pageHome" data-rel="back"></a>
            <h1 class="page-title-bar">预订须知</h1>
        </div>
    </header>
    <!-- 公用顶部 -->
    <div class="page-content">
        <div class="bk-document-page">
            <div class="bk-content-wrap">
                {Common::content_image_width($GLOBALS['cfg_spot_order_agreement'],750,0)}
            </div>
        </div>
    </div>
</div>
<!--预订协议-->
{/if}

<div id="ticketInfo" class="hide">
    <div class="product-show-info">
        <div class="info-show-bar">门票说明<i class="close-icon" id="closeTicketLayer"></i></div>
        <div class="info-show-area" style="bottom: 0;">
            <div class="info-primary-hd">
                <h4 class="tit">{$suit_info['title']} - {$suit_info['tickettype_name']} </h4>
                <div class="attr">
                    <!--退款条件-->
                    {if $suit_info['refund_restriction']==0}
                    <span class="item">无条件退</span>
                    {elseif $suit_info['refund_restriction']==1}
                    <span class="item">不可退改</span>
                    {elseif $suit_info['refund_restriction']==2}
                    <span class="item">有条件退</span>
                    {/if}
                    <!--预订方式-->
                    <span class="item">{$suit_info['paytype_name']}</span>
                    <!--支付方式-->
                    {if $suit_info['pay_way']==1}
                    <span class="item">线上支付</span>
                    {elseif $suit_info['pay_way']==2}
                    <span class="item">线下支付</span>
                    {elseif $suit_info['pay_way']==3}
                    <span class="item">线上支付</span>
                    <span class="item">线下支付</span>
                    {/if}
                </div>
            </div>
            <div class="info-other-bd">
                <h4 class="tit">预订时间</h4>
                <div class="txt">
                    {if !empty($suit_info['day_before_des_mobile'])}
                    {$suit_info['day_before_des_mobile']}
                    {else}当天24:00前可预订{/if}
                </div>
            </div>
            <div class="info-other-bd">
                <h4 class="tit">有效期</h4>
                <div class="txt">
                    {if !empty($suit_info['effective_days'])}
                    {$suit_info['effective_before_days_des']}
                    {else}验票当天24:00前{/if}
                </div>
            </div>
            {if !empty($suit_info['get_ticket_way'])}
            <div class="info-other-bd">
                <h4 class="tit">取票说明</h4>
                <div class="txt">{$suit_info['get_ticket_way']}</div>
            </div>
            {/if}
            {if !empty($suit_info['description'])}
            <div class="info-other-bd">
                <h4 class="tit">门票说明</h4>
                <div class="txt editor-content clearfix">
                    {Common::content_image_width($suit_info['description'],750,0)}
                </div>
            </div>
            {/if}
        </div>
    </div>
</div>
<!-- 门票说明详情 -->

<div class="page out" id="commonUse">
    <header>
        <div class="header_top">
            <a class="back-link-icon" href="#pageHome" data-rel="back"></a>
            <h1 class="page-title-bar">选择常用旅客</h1>
        </div>
    </header>
    <!-- 公用顶部 -->
    <div class="page-content">

        <div class="linkman-group" style="top:0">
            {st:member action="linkman" memberid="$userinfo['mid']" return="tourerlist"}
            <ul class="linkman-list clearfix">
                {loop $tourerlist $tourer}
                <li data-fields='{json_encode($tourer)}'>
                    <span class="checkbox-label"><i class="check-icon"></i></span>
                    <div class="info">
                        <strong class="name">{$tourer['linkman']}</strong>
                        <span class="code">{$tourer['cardtype']}  {$tourer['idcard']}</span>
                    </div>
                </li>
                {/loop}
            </ul>
            <a class="save-info-btn" href="#pageHome" data-rel="back">确认</a>
        </div>
    </div>
</div>
<div class="page out" id="choose_date">
    <div class="header_top bar-nav">
        <a class="back-link-icon" href="javascript:;" data-rel="back"></a>
        <h1 class="page-title-bar">选择日期</h1>
    </div>
    <!-- 公用顶部 -->
    <div class="page-content full-page">
        <div class="calendar-container">
        </div>
        <!-- 选择日期 -->
    </div>
</div>
<!--可用优惠券选择-->
{if St_Functions::is_normal_app_install('coupon')}
    {php}$coupon_list = Model_Coupon::get_pro_coupon($typeid,$info['id']);{/php}
    <div class="page out" id="useCoupon">
        <header>
            <div class="header_top">
                <a class="back-link-icon"  href="javascript:;" onclick="window.history.go(-1)" data-ajax="false"></a>
                <h1 class="page-title-bar">使用优惠券</h1>
            </div>
        </header>
        <!-- 公用顶部 -->
        <div class="page-content">
            <div class="wrap-content">
                <div class="use-coupon-block clearfix">
                    <ul class="coupon-list">
                        {loop $coupon_list $l}
                        <li data-id="{$l['roleid']}" couponprice="{if $l['type']==1} {$l['amount']}折{else}{Currency_Tool::symbol()}{$l['amount']}{/if}" cname="{$l['name']}">
                            <div class="attr-zs">通用券</div>
                            <div class="item-l fl">
                                <strong class="type">{$l['name']}</strong>
                                <p class="txt">品类限制：{if $l['typeid']==9999}部分{$l['typename']}产品可用{else}无品类限制{/if}</p>
                                <p class="date">有效期：{if $l['isnever']==1}截止{$l['endtime']}{else}永久有效{/if}</p>
                            </div>
                            <div class="item-r fr">
                                <span class="jg">{if $l['type']==1} {$l['amount']}折{else}{Currency_Tool::symbol()}{$l['amount']}{/if}</span>
                                <span class="sm">满{Currency_Tool::symbol()}{$l['samount']}可用</span>
                                <i class="use-label"></i>
                            </div>
                        </li>
                        {/loop}

                    </ul>
                </div>
                <!-- 使用列表 -->
            </div>
        </div>
    </div>
    <script>
        $(function(){

            //选择优惠券
            $('#useCoupon .coupon-list li').click(function() {
                var totoalprice =  $('#org_total_price').val();
                var this_obj = $(this);
                var couponprice= this_obj.attr('couponprice');

                if ($(this).hasClass('choosed'))
                {
                    this_obj.removeClass('choosed');
                    coupon_reset();
                    if(typeof(get_total_price)=='function')
                    {
                        get_total_price(1);
                    }
                }
                else
                {
                    this_obj.addClass('choosed');
                    this_obj.siblings().removeClass('choosed');
                    var couponid = this_obj.data('id');
                    var typeid = '{$typeid}';
                    var proid = "{$info['id']}";
                    var couponname= this_obj.attr('cname');
                    check_and_set_coupon(couponid,totoalprice,typeid,proid,couponname,couponprice);
                }
            })
        })
        /**
         * 检查优惠券是否可用
         */
        function check_and_set_coupon(couponid,totalprice,typeid,proid,couponname,amount)
        {
            var startdate = $('input[name=startdate]').val();
            $.ajax({
                type:"post",
                url:SITEURL+'coupon/ajax_check_samount',
                data:{couponid:couponid,totalprice:totalprice,typeid:typeid,proid:proid,startdate:startdate},
                datatype:'json',
                success:function(data){
                    data = JSON.parse(data);
                    if(data.status==1)
                    {
                        var coupon_price=totalprice-data.totalprice;
                        $('#couponid').val(couponid);
                        $("#coupon_price").val(coupon_price);
                        $('#discount_con a.all span.more-type').html('<em class="org">-'+amount+'</em><i class="more-ico"></i>');
                        //$('.coupon_type').html('<strong>优惠券</strong><em class="type">'+amount+'</em>');
                        window.history.go(-1);
                        if(typeof(get_total_price)=='function')
                        {
                            get_total_price(1);
                        }
                    }
                    else
                    {
                        $.layer({
                            type:1,
                            icon:2,
                            text:'不满足使用条件',
                            time:1000
                        });
                    }
                }
            })


        }

        //重置优惠券
        function coupon_reset()
        {
            $("#useCoupon .coupon-list ul .choosed").removeClass('choosed');
            $('#useCoupon #couponid').val(0);
            $("#useCoupon #coupon_price").val(0);
            $('#useCoupon .use_coupon_btn').html('点击选择<i class="more-ico" ></i>');
            {if empty($coupon_list)}
            $('#useCoupon .coupon_type').html('<strong>优惠券</strong><em class="type">暂无可用优惠券</em>');
            {else}
            $('#useCoupon .coupon_type').html('<strong>优惠券</strong>');
            {/if}
        }
    </script>
{/if}
{request "pub/code"}



{if St_Functions::is_normal_app_install('red_envelope')}{request "envelope/product_book/typeid/$typeid/"}{/if}
<script>
    var init_suitid = "{$suitid}";
    var CURRENCY_SYMBOL = "{Currency_Tool::symbol()}";
    var productid = "{$info['id']}";
    //  var field_arr={json_encode($fieldlist)};
    $(document).ready(function () {
        //门票说明
        $('#ticketInfoentry').on('click',function(){
            var index = layer.open({
                type: 1,
                content: $('#ticketInfo').html(),
                anim: 'up',
                className: 'layer-show-content',
                success: function(){
                    $('body').on('click','#closeTicketLayer',function(){
                        layer.close(index);
                    })
                }
            });
        });

        //弹出套餐选择菜单
        $("#suit_btn").click(function () {
            $("#suit_list").show();
        });

        //套餐选择
        $("#suit_list .tc-wrapper ul li").click(function () {
            $(this).addClass('active');
            $(this).siblings().removeClass('active');
            var suitid = $(this).data('id');

            var paytype = $(this).data('paytype');
            var price = $(this).data('price');
            var dingjin = $(this).data('dingjin');
            var suitname = $(this).data('suitname');
            var paytype_name = $(this).data('paytype_name');
            var startdate = $(this).attr('date-start');
            //如果不是全款支付，则没有优惠
            if (paytype == 1 || paytype == 3)
            {
                $("#discount_con").show();
                $(".board_discount").show();
            }
            else
            {
                $("#discount_con").hide();
                $(".board_discount").hide();
            }
            $("#txt_paytype").text(paytype_name);
            $("#txt_suitname").text(suitname);
            $("#board_suitname").text(suitname);
            $("#field_suitid").val(suitid);
            $("#field_dingjin").val(dingjin);
            $("#field_paytype").val(paytype);

//            $("#field_price").val(price);
//            $("#txt_price").html(CURRENCY_SYMBOL + price);
//            $("#field_startdate").val(startdate);
//            $("#chooseBookingDate span[data-date='"+startdate+"']").addClass('cur');
            //$("#chooseBookingDate span[data-date='"+startdate+"'] span.pri").html(CURRENCY_SYMBOL+price);
//            if($("#chooseBookingDate span.cur").length<1) {
//                $("#chooseBookingDate a").html('<span class="date">'+startdate+'<i class="more-icon"></i></span><span class="pri">'+CURRENCY_SYMBOL+price+'起</span>');
//            }
            $('#suit_list').hide();
            get_total_price();
        });

        //默认选中一个套餐
        if (init_suitid && init_suitid != 0) {
            $("#suit_list .tc-wrapper ul .suit_item_" + init_suitid).trigger('click');
        }
        else
        {
            $("#suit_list .tc-wrapper ul li:first").trigger('click');
        }

        //数量修改
        $('.sub-btn,.add-btn').click(function () {
            if(!$("#field_startdate").val())
            {
                $.layer({type: 1, icon: 2, time: 1000, text: '请选择门票使用日期'});
                return false;
            }
            var num = $(this).siblings(".num-text").val();
            var num = !num ? 0 : parseInt(num);
            if ($(this).is('.sub-btn')) {
                num = num > 0 ? --num : 0;
            }
            else {
                num++;
            }
            var total=$("#chooseBookingDate>.cur").attr('data-total');
            if(total>0&&total<num){
                $.layer({type: 1, icon: 2, time: 1000, text: '所选日期的余票不足您需购买的门票量'});
                //$("#chooseBookingDate>.cur").removeClass('cur');
                //$("#field_startdate").val('');
                return false;
            }
            $(this).siblings(".num-text").val(num);
            refresh_tourers(num);
            get_total_price();
        });

        //预订须知
        $(".agreement-block .check-box").on("click", function () {
            if (!$(this).hasClass("on")) {
                $(this).addClass("on");
                //$(".receipt-item").show();
                $("#agreement_order").val(1);
            }
            else {
                $(this).removeClass("on");
                //$(".receipt-item").hide();
                $("#agreement_order").val(0);
            }
        });

        //明细列表
        $("#order-show-list").click(function () {
            //$("#fee-box").removeClass("hide");
            $("#fee-box").toggle();
        });
        $("#fee-box").click(function () {
            $(this).hide()
        })

        //游客选择
        $(".linkman-list li .check-icon").click(function () {
            var tourer = $(this).parents('li:first').data('fields');
            if ($(this).hasClass('on')) {
                $(this).removeClass('on');
                switch_tourer(tourer, 1);
            }
            else {
                if (switch_tourer(tourer)) {
                    $(this).addClass('on');
                }
            }
        });

        //证件类型弹出框
        $("#cardtype_con").click(function () {
            $(this).hide();
        })
        $("#cardtype_con .list li").click(function () {

        });

        $("#roombalance_type_btn").click(function () {
            $("#roombalance_type_con").show();
        });
        $("#roombalance_type_con ul li").click(function () {
            var txt = $(this).text();
            var val = $(this).attr('val');
            $("#field_roombalance_paytype").val(val);
            $("#txt_roombalance_type").text(txt);
            get_total_price(0);

        });
        $("#roombalance_type_con").click(function () {
            $(this).hide();
        });


        //证件类型选择
        $(document).on('click', '.tourer_cardtype', function () {
            $("#cardtype_con").show();
            $("#cardtype_con .list li").unbind();
            var tourer_field = this;
            $("#cardtype_con .list li").click(function () {
                $(tourer_field).val($(this).text());
            });
        })

        //游客性别选择
        $(document).on('click', '.tourer_item_sex .check-label-item', function () {
            $(this).addClass('checked');
            $(this).siblings().removeClass('checked');
            var val = $(this).data('value');
            $(this).siblings('input:hidden').val(val);
        })

        //日期选择
        $("#chooseBookingDate>span").click(function () {
            var date_obj=$(this);
            var url = SITEURL + 'spot/ajax_price_day';
            var suitid = $("#field_suitid").val();
            var date =date_obj.attr('data-date');
            if(!date){
                return false;
            }
            var old_dingnum=$("#field_dingnum").val();
            var total=date_obj.attr('data-total');
            if(total>0&&total<old_dingnum){
                $.layer({type: 1, icon: 2, time: 1000, text: '所选日期的余票不足您需购买的门票量'});
                return false;
            }
            $.ajax({
                type: 'GET',
                url: url,
                data: {suitid: suitid, productid: productid,date:date},
                dataType: 'json',
                success: function (data) {
                    if(data.number!=0)
                    {
                        if(data.number>0&&data.number<old_dingnum)
                        {
                            $("#field_price").val(0);
                            $("#field_startdate").val('');
                            return false;
                        }else{
                            date_obj.siblings().removeClass('cur');
                            date_obj.addClass('cur');
                            $("#field_price").val(data.price);
                            $("#field_startdate").val(date);
                        }
                        get_total_price();
                    }
                    //$("#choose_date").show();
                }
            });
        });

        //日历选择
        $("#chooseBookingDate a").click(function () {
            var date_obj=$(this);
            $(".calendar-container").html('');
            var url = SITEURL + 'spot/ajax_price_calendar';
            var suitid = $("#field_suitid").val();
            $.ajax({
                type: 'GET',
                url: url,
                data: {suitid: suitid, productid: productid},
                dataType: 'html',
                success: function (data) {
                    $(".calendar-container").html(data);
                    var date =date_obj.attr('data-date');
                    if(date){
                        $("tr.calendar-bd>td>div").removeClass('active');
                        $("tr.calendar-bd>td[date='"+date+"']>div").addClass('active');
                    }
                    $("#choose_date").show();
                }
            });
        });


        //第一次刷新游客信息
        refresh_tourers();

        //选中游客
        function switch_tourer(tourer, isdelete) {
            var isset = false;
            $("#tourer_con .block-item ul").each(function () {
                if (isset) {
                    return;
                }
                var tourername = $(this).find('.tourer_tourername').val();
                if (isdelete && tourername == tourer['linkman']) {
                    $(this).find('input').val('');
                    isset = true;
                }
                else if (!isdelete && !tourername) {
                    for (var i in tourer) {
                        $(this).find('.tourer_' + i).val(tourer[i]);

                        if (i == 'cardtype') {
                            $(this).find('.t_cardtype_txt').text(tourer[i]);
                            $(this).find('.field_t_cardtype').val(tourer[i]);
                        }
                        if (i == 'sex') {
                            if (tourer[i] == 0 || tourer[i] == '女') {
                                $(this).find('.sex_female').trigger('click');
                            }
                            else {
                                $(this).find('.sex_male').trigger('click');
                            }
                        }

                    }
                    isset = true;
                }

            });
            return isset;
        }


        //刷新游客
        function refresh_tourers() {
            if ($("#tourer_con").length <= 0) {
                return;
            }
            var num = parseInt($("#field_dingnum").val());
            var exist_num = $("#tourer_con .block-item ul").length;
            exist_num = !exist_num ? 0 : exist_num;
            var only_one=$("#tourer_con").attr('data-max');
            if(exist_num==1&&only_one==1){
                return;
            }
            if (exist_num > num) {
                var cur_index = num - 1;
                $("#tourer_con .block-item ul:gt(" + cur_index + ")").remove();
            }
            else
            {
                for (var i = exist_num; i < num; i++) {
                    var html = gen_tourer(i + 1);

                    $("#tourer_con .block-item").append(html);
                    $(".tourer_item_sex .check-label-item").css('cursor', 'pointer');
                }
            }
            $(".t_cardtype").click(function () {
                // $(this).unbind();
                $("#cardtype_con").show();
                var cur_field = this;
                $("#cardtype_con li").unbind();
                $("#cardtype_con li").click(function () {
                    var val = $(this).text();
                    $(cur_field).find('.t_cardtype_txt').text(val);
                    $(cur_field).find('.field_t_cardtype').val(val);
                });
            });
        }

        //生成游客
        function gen_tourer(index) {
            var fields_str=$("#tourer_con").attr('data-field');
            if(fields_str){
                var fields_arr=fields_str.split(",");
                var html = '';
                html += '<ul><li><strong class="item-bt no-style">游客' + index + '</strong></li>';

                if($.inArray("tourername",fields_arr)>=0)
                {
                    html += '<li><strong class="item-hd no-style">姓名</strong>';
                    html += '<input type="text" class="write-info tourer_linkman tourer_tourername" fieldname="tourername" name="t_tourername[' + index + ']" placeholder="与乘客证件一致">';
                    html += '<span class="nd">(必填)</span></li>';
                }
                if($.inArray("sex",fields_arr)>=0)
                {
                    html += '<li class="tourer_item_sex">';
                    html += '<strong class="item-hd no-style">性别</strong>';
                    html += '<div class="sex-bar">';
                    html += '<span class="check-label-item sex_male checked" data-value="男"><i class="icon"></i>男</span>';
                    html += '<span class="check-label-item sex_female" data-value="女"><i class="icon"></i>女</span>';
                    html += '<input type="hidden" fieldname="sex" name="t_sex[' + index + ']" value="男"/>';
                    html += '</div></li>';
                }
                if($.inArray("mobile",fields_arr)>=0)
                {
                    html += '<li><strong class="item-hd no-style">手机号</strong>';
                    html += '<input type="text" class="write-info tourer_mobile" fieldname="mobile" name="t_mobile[' + index + ']" placeholder="请输入手机号"></li>';
                }
                if($.inArray("cardnumber",fields_arr)>=0)
                {
                    html += '<li><strong class="item-hd no-style t_cardtype"><span class="t_cardtype_txt">身份证</span><input type="hidden" fieldname="cardtype" class="field_t_cardtype" name="t_cardtype[' + index + ']" value="身份证"/><i class="down-ico"></i></strong>';
                    html += '<input type="text" class="write-info tourer_idcard" fieldname="cardnumber" name="t_cardnumber[' + index + ']" placeholder="请输入证件号码">';
                    html += '<span class="nd">(必填)</span></li>';
                }

                html += '</ul>';
                return html;
            }


        }
    });

    function choose_day(ele) {
        var  choose_time =Date.parse(new Date());
        if(!window.last_choose_time)
        {
            window.last_choose_time = choose_time;
        }
        else
        {
            var interval_seconds =  choose_time-window.last_choose_time;
            if(interval_seconds<2000)
            {
                return;
            }
            else
            {
                window.last_choose_time = choose_time;
            }
        }

        $("#choose_date div.calendar-container").find('td div.item.opt').removeClass('active');
        var adultprice = $(ele).attr('adultprice');
        var date = $(ele).attr('date');
        var number = $(ele).attr('number');
        var old_dingnum=$("#field_dingnum").val();
        if(number>0&&old_dingnum>number){
            $.layer({type: 1, icon: 2, time: 1000, text: '余票不足您所购票数'});
            return false;
        }
        $(ele).find('div.item.opt').addClass('active');
        $("#chooseBookingDate a.item-date").siblings().removeClass('cur');
        var selected=0;
        $("#chooseBookingDate>span.item-date").each(function () {
            if(selected==0&&date==$(this).attr('data-date'))
            {
                $(this).addClass('cur').attr('data-total',number).attr('data-date',date);
                selected=1;
            }
        });
        if(selected==0)
        {
            $("#chooseBookingDate a.item-date").addClass('cur').attr('data-total',number).attr('data-date',date);
            $("#chooseBookingDate a.item-date span.date").html(date+'<i class="more-icon"></i>');
            $("#chooseBookingDate a.item-date span.pri").text(CURRENCY_SYMBOL + adultprice);
        }
        $("#field_price").val(adultprice);
        $("#field_startdate").val(date);
     window.history.back();
        get_total_price();
    }

</script>

<!--预订部分JS-->
<script>
    var lock_bookbtn = 0
    $(function () {
        $(".now-booking-btn").click(function () {
            if(lock_bookbtn==1){
                return false
            }
            var check_status = check_form();
            if (check_status) {
                lock_bookbtn = 1
                $("#orderfrm").submit();
            }
        });


        function check_form() {
            var suitid = $("#field_suitid").val();
            var dingnum = $("#field_dingnum").val();
            var linkman = $("#field_linkman").val();
            var linktel = $("#field_linktel").val();
            var startdate = $("#field_startdate").val();
            if($("#agreement_order").length>0)
            {
                var agreement_order=$("#agreement_order").val();
                if (agreement_order!=1) {
                    $.layer({type: 1, icon: 2, time: 1000, text: '请先仔细阅读我们的预订条款内容'});
                    return false;
                }
            }

            if (!suitid) {
                $.layer({type: 1, icon: 2, time: 1000, text: '请至少选择一个套餐'});
                return false;
            }

            if (!startdate) {
                $.layer({type: 1, icon: 2, time: 1000, text: '请先选择使用日期'});
                return false;
            }

            //预订数量
            if (dingnum < 1) {
                $.layer({type: 1, icon: 2, time: 1000, text: '预订数量不能为0'});
                return false;
            }

            //联系人
            if (!linkman) {
                $.layer({type: 1, icon: 2, time: 1000, text: '联系人不能为空'});
                return false;
            }

            if (!linktel) {
                $.layer({type: 1, icon: 2, time: 1000, text: '联系人手机号码不能为空'});
                return false;
            }
            if (!Validate.mobile(linktel)) {
                $.layer({type: 1, icon: 2, time: 1000, text: '联系人手机号码格式错误'});
                return false;
            }


            //游客所有信息
            var is_tourer_checked = false;
            $("#tourer_con .block-item ul li input").each(function () {
                if (is_tourer_checked) {
                    return;
                }
                var desc = $(this).siblings('.item-hd').text();
                var fieldname = $(this).attr('fieldname');
                desc = fieldname == 'cardtype' ? '证件类型' : desc;
                var value = $(this).val();
                if (fieldname == 'mobile') {
                    if (!value) {
                        $.layer({type: 1, icon: 2, time: 1000, text: '游客手机号码不能为空'});
                        is_tourer_checked = true;
                    }
                    else if (!Validate.mobile(value)) {
                        $.layer({type: 1, icon: 2, time: 1000, text: '游客手机号码格式错误'});
                        is_tourer_checked = true;
                    }
                }
                else if (fieldname == 'cardnumber') {
                    var cardtype = $(this).parents('li:first').find('.field_t_cardtype').val();
                    if (cardtype == '身份证') {
                        if (!Validate.idcard(value)) {
                            $.layer({type: 1, icon: 2, time: 1000, text: '游客身份证格式错误'});
                            is_tourer_checked = true;
                        }
                    }
                    else {
                        if (!value) {
                            $.layer({type: 1, icon: 2, time: 1000, text: '游客' + desc + '不能为空1'});
                            is_tourer_checked = true;
                        }
                    }
                }
                else {
                    if (!value) {
                        $.layer({type: 1, icon: 2, time: 1000, text: '游客' + desc + '不能为空2'});
                        is_tourer_checked = true;
                    }
                }
            });
            if (is_tourer_checked) {
                return false;
            }

            return true;

        }
    })
</script>


<!--公共函数JS-->
<script>


    //更新总价
    function get_total_price(a) {
        if (!a) {
            on_orgprice_changed();
        }
        var adultprice = parseFloat($('#field_price').val());
        var dingnum = parseInt($('#field_dingnum').val());

        var total_num = dingnum;
        var total = STMath.mul(dingnum , adultprice);


        var org_totalprice = total;
        $("#board_org_total").html(CURRENCY_SYMBOL + org_totalprice);
        $("#org_total_price").val(org_totalprice);


        //积分抵现
        var jifentprice = 0;
        if (typeof(jifentprice_calculate) == 'function') {
            jifentprice = jifentprice_calculate();
        }
        $("#board_jifentprice").html(CURRENCY_SYMBOL + jifentprice);

        total = STMath.sub(total,jifentprice);

        //设置优惠券
        var coupon_price = $('#coupon_price').val();
        coupon_price = !coupon_price ? 0 : coupon_price;
        if (coupon_price) {
            total = STMath.sub(total,coupon_price) ;
        }
        $("#board_coupon").html(CURRENCY_SYMBOL + coupon_price);

        //设置红包
        var envelope_price = $('#envelope_price').val();
        envelope_price=!envelope_price?0:envelope_price;
        if(envelope_price)
        {
            total = total - envelope_price;
        }
        $("#board_envelope").html(CURRENCY_SYMBOL+envelope_price);


        if (total < 0) {
            var negative_params = {
                totalprice: total,
                jifentprice: jifentprice,
                couponprice: coupon_price,
                org_totalprice: org_totalprice
            };
            on_negative_totalprice(negative_params);
            return;
        }

        var total_dingjin = 0;
        var paytype = $("#field_paytype").val();
        if (paytype == 2) {
            var dingjin = $("#field_dingjin").val();
            total_dingjin =  STMath.mul(dingjin , total_num);
            var underline_total = total - total_dingjin;
            $("#bbar_paytotal").html("订金支付：" + CURRENCY_SYMBOL + total_dingjin);
            $("#board_dingjin").html("在线支付(定金)" + CURRENCY_SYMBOL + total_dingjin + "+到店付款" + CURRENCY_SYMBOL + underline_total);
            $("#board_dingjin").show();
            $("#board_total").html(CURRENCY_SYMBOL + total);
        } else {
            var total_final = total;
            $("#bbar_paytotal").html("应付总额：" + CURRENCY_SYMBOL + total_final);
            $("#board_dingjin").hide();
            $("#board_total").html(CURRENCY_SYMBOL + total_final);
        }

    }

    //当总价小于0时
    function on_negative_totalprice(params) {
        layer.open({
            type:3,
            content: '优惠价格超过产品总价，请重新选择优惠策略',
            btn: ['{__("OK")}']
        });
        if (typeof(coupon_reset) == 'function') {
            coupon_reset();
        }
        if (typeof(jifentprice_reset) == 'function') {
            jifentprice_reset();
        }
        get_total_price(1);
    }
    //当原始价格发生改变时
    function on_orgprice_changed() {
        if (typeof(coupon_reset) == 'function') {
            coupon_reset();
        }
        if (typeof(jifentprice_reset) == 'function') {
            jifentprice_reset();
        }
    }

</script>

</body>
</html>
